home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
challenge
/
12.04-Apr96
/
LifeTestCode DR3.sit
/
Life TestCode DR3
/
LifeWindow.c
< prev
next >
Wrap
Text File
|
1996-04-03
|
6KB
|
230 lines
#define JRB 0
#define SHOWGRID 0
/* LifeWindow.c */
/* ©Ludovic Nicolle 1996 */
#include "LifeWindow.h"
extern Boolean gDrawGrid;
extern Boolean gToroidLike;
extern short gToroidLimit;
void DisplayCells(GrafPtr lifeC, WindowPtr screenC, Rect *screenR)
{
Point lifeSize, screenSize, hvRatio;
short gRatio;
Rect lifeRect, outRect, lifetor, screentor;
short i;
GrafPtr savePort;
GetPort(&savePort);
SetPort(screenC);
if (lifeC->portBits.baseAddr == nil)
{
EraseRect(screenR);
SetPort(savePort);
return;
}
lifeSize.h = lifeC->portBits.bounds.right -
lifeC->portBits.bounds.left;
lifeSize.v = lifeC->portBits.bounds.bottom -
lifeC->portBits.bounds.top;
screenSize.h = screenR->right - screenR->left;
screenSize.v = screenR->bottom - screenR->top;
gRatio = GiveRatio(lifeC, screenR, &hvRatio);
if (gRatio == 0)
{/*we don't have enough place to draw the entire bitmap*/
if ((hvRatio.v == 0 ) && (hvRatio.h == 0))
{
lifeRect = *screenR;
OffsetRect(&lifeRect, lifeRect.left, lifeRect.top);
outRect = *screenR;
} else
{ /*have to clip only the direction where ratio = 0*/
lifeRect = lifeC->portBits.bounds;
lifeRect.bottom = lifeRect.top +
(!hvRatio.v ? screenSize.v:lifeSize.v);
lifeRect.right = lifeRect.left +
(!hvRatio.h ? screenSize.h:lifeSize.h);
outRect = lifeRect;
OffsetRect(&outRect, screenR->left, screenR->top);
}
} else
{
SetRect(&outRect, screenR->left, screenR->top,
screenR->left + gRatio * lifeSize.h,
screenR->top + gRatio * lifeSize.v);
lifeRect = lifeC->portBits.bounds;
}
OffsetRect(&outRect, gRatio, gRatio);
CopyBits(&lifeC->portBits, &((GrafPtr)screenC)->portBits,
&lifeRect, &outRect, srcCopy, screenC->visRgn);
if ((gRatio > gToroidLimit) && gToroidLike)
{
lifetor = lifeRect;
lifetor.top = lifetor.bottom - 1;
screentor = outRect;
screentor.top = outRect.top - gRatio;
screentor.bottom = outRect.top;
CopyBits(&lifeC->portBits, &((GrafPtr)screenC)->portBits,
&lifetor, &screentor, srcCopy, screenC->visRgn);
lifetor = lifeRect;
lifetor.bottom = lifetor.top + 1;
screentor = outRect;
screentor.top = outRect.bottom;
screentor.bottom = outRect.bottom + gRatio;
CopyBits(&lifeC->portBits, &((GrafPtr)screenC)->portBits,
&lifetor, &screentor, srcCopy, screenC->visRgn);
outRect.top -= gRatio;
// outRect.top -= 1;
outRect.bottom += gRatio;
// outRect.bottom += 1;
lifetor = outRect;
lifetor.left = lifetor.right - gRatio;
screentor = outRect;
screentor.left = outRect.left - gRatio;
screentor.right = outRect.left;
CopyBits(&((GrafPtr)screenC)->portBits,
&((GrafPtr)screenC)->portBits,
&lifetor, &screentor, srcCopy, screenC->visRgn);
lifetor = outRect;
lifetor.right = lifetor.left + gRatio;
screentor = outRect;
screentor.left = outRect.right;
screentor.right = outRect.right + gRatio;
CopyBits(&((GrafPtr)screenC)->portBits,
&((GrafPtr)screenC)->portBits,
&lifetor, &screentor, srcCopy, screenC->visRgn);
/* if I decide to add other feature later. Unuseful now */
outRect.top += gRatio;
// outRect.top += 1;
outRect.bottom -= gRatio ;
// outRect.bottom -= 1;
}
InsetRect(&outRect, -1, -1);
FrameRect(&outRect);
InsetRect(&outRect, 1, 1);
if ((gRatio> gToroidLimit) && gDrawGrid) {
for (i=1; i<=lifeSize.h; ++i) {
MoveTo(outRect.left + i*gRatio, outRect.top);
Line(0,gRatio*lifeSize.v);
}
for (i=1; i<=lifeSize.v; ++i) {
MoveTo(outRect.left, outRect.top + i*gRatio);
Line(gRatio*lifeSize.h,0);
}
}
SetPort(savePort);
}
void ClickSet(GrafPtr lifeC, WindowPtr screenC, Rect *screenR,
Point *clickPt, short *ratio)
{
Point lifeSize, screenSize, clickPos, hvRatio;
Rect lifeRect, r;
GrafPtr savePort;
short gRatio;
Point topleftP;
GetPort(&savePort);
gRatio = GiveRatio(lifeC, screenR, &hvRatio);
/* zut */
lifeSize.h = lifeC->portBits.bounds.right -
lifeC->portBits.bounds.left;
lifeSize.v = lifeC->portBits.bounds.bottom -
lifeC->portBits.bounds.top;
screenSize.h = screenR->right - screenR->left;
screenSize.v = screenR->bottom - screenR->top;
if (gRatio == 0)
{/*we don't have enough place to draw the entire bitmap*/
if ((hvRatio.v == 0 ) && (hvRatio.h == 0))
{
lifeRect = *screenR;
} else
{ /*have to clip only the direction where ratio = 0*/
lifeRect = lifeC->portBits.bounds;
lifeRect.bottom = lifeRect.top +
(!hvRatio.v ? screenSize.v:lifeSize.v);
lifeRect.right = lifeRect.left +
(!hvRatio.h ? screenSize.h:lifeSize.h);
OffsetRect(&lifeRect, screenR->left, screenR->top);
}
} else
{
SetRect(&lifeRect, screenR->left, screenR->top,
screenR->left + gRatio * lifeSize.h,
screenR->top + gRatio * lifeSize.v);
}
OffsetRect(&lifeRect, gRatio, gRatio);
/* zut */
if (!PtInRect(*clickPt, &lifeRect))
return;
topleftP.h = lifeRect.left;
topleftP.v = lifeRect.top;
if (gRatio == 0)
gRatio = 1; /* allow clickset on visible parts
of large bitmap*/
clickPos.h = (clickPt->h - topleftP.h + 0) / gRatio;
clickPos.v = (clickPt->v - topleftP.v + 0) / gRatio;
SetPort(lifeC);
SetRect(&lifeRect, clickPos.h, clickPos.v,
clickPos.h + 1, clickPos.v + 1);
InvertRect(&lifeRect);
SetPort(screenC);
SetRect(&r,(clickPos.h)*gRatio,(clickPos.v)*gRatio,
(clickPos.h+1)*gRatio, (clickPos.v+1)*gRatio);
OffsetRect(&r,topleftP.h,topleftP.v);
InvertRect(&r);
InvalRect(&r);
if ((clickPos.h == lifeC->portBits.bounds.left) ||
(clickPos.h == lifeC->portBits.bounds.right - 1) ||
(clickPos.v == lifeC->portBits.bounds.top) ||
(clickPos.v == lifeC->portBits.bounds.bottom - 1))
{
InvalRect(screenR);
}
SetPort(savePort);
SetPt(clickPt, topleftP.h + gRatio * clickPos.h,
topleftP.v + gRatio * clickPos.v);
*ratio = gRatio;
}
short GiveRatio(GrafPtr lifeC, Rect *screenR, Point *hvRatio)
{
Point lifeSize, screenSize;
/* we add 2 to the cells bitmap size to allow the display
of the opposite band of data */
lifeSize.h = lifeC->portBits.bounds.right -
lifeC->portBits.bounds.left + 2;
lifeSize.v = lifeC->portBits.bounds.bottom -
lifeC->portBits.bounds.top + 2;
screenSize.h = screenR->right - screenR->left;
screenSize.v = screenR->bottom - screenR->top;
hvRatio->v = screenSize.v / lifeSize.v;
hvRatio->h = screenSize.h / lifeSize.h;
return((hvRatio->v > hvRatio->h) ? hvRatio->h : hvRatio->v);
}